package com.example.animaltiontext_1;

import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.util.Pair;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class TranslationFromActivity extends AppCompatActivity {
    private Button mbutton1;
    private Button mbutton2;
    private Button mbutton3;
    private Button mbutton4;
    private ImageView mImage;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_from);
        mbutton1 = findViewById(R.id.button1);
        mbutton2 = findViewById(R.id.button2);
        mbutton3 = findViewById(R.id.button3);
        mbutton4 = findViewById(R.id.button4);
        mImage = findViewById(R.id.image);
        addListener(mbutton1,1);
        addListener(mbutton2,2);
        addListener(mbutton3,3);
        addListener(mbutton4,4,
                new Pair<>(mbutton1, "button1"),
                new Pair<>(mbutton2,"button2"),
                new Pair<>(mbutton3,"button3"),
                new Pair<>(mbutton4,"button4"),
                new Pair<>(mImage,"mImage"));
    }
    private void addListener(Button button,int flag, Pair<View, String>... sharedElements){
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(TranslationFromActivity.this,TranslationToActivity.class);
                intent.putExtra("flag",flag);
                startActivity(
                        intent,
                        ActivityOptions.makeSceneTransitionAnimation(TranslationFromActivity.this,sharedElements).toBundle()
                );
            }
        });
    }
}
